﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using SelectPdf;


namespace RosarioFinanzas.Mercados
{
    public partial class Historico : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            //string dia = Page.Request.QueryString["dia"].ToString();
            //string mes = Page.Request.QueryString["mes"].ToString();
            //string año = Page.Request.QueryString["año"].ToString();
            
        }

        [WebMethod]
        public static string strFecha(string str)
        {

            string[] dayarray = { "Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado" };
            string[] montharray = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
            var daym = DateTime.Today.Day.ToString();
            var year = DateTime.Today.Year.ToString();
            var day = Convert.ToInt32(DateTime.Today.DayOfWeek);
            var month = DateTime.Today.Month - 1;
            return dayarray[day] + ", " + daym + " de " + montharray[month] + " del " + year + " ";

        }

        protected void ConvertirHTMLtoPDF(object sender, EventArgs e)
        {
            try
            {

                // read parameters from the webpage
                string url = Request.Url.AbsoluteUri;

                PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), "A4", true);

                PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), "Portrait", true);

                int webPageWidth = 1024;
                try
                {
                    webPageWidth = Convert.ToInt32("1024");
                }
                catch { }

                int webPageHeight = 0;
                try
                {
                    webPageHeight = Convert.ToInt32("768");
                }
                catch { }

                // instantiate a html to pdf converter object
                HtmlToPdf converter = new HtmlToPdf();

                // set converter options
                converter.Options.PdfPageSize = pageSize;
                converter.Options.PdfPageOrientation = pdfOrientation;
                converter.Options.WebPageWidth = webPageWidth;
                converter.Options.WebPageHeight = webPageHeight;
                converter.Options.MarginTop = 10;
                converter.Options.MarginLeft = 10;
                converter.Options.MarginRight = 10;
                converter.Options.MarginBottom = 10;


                // create a new pdf document converting an url
                PdfDocument doc = converter.ConvertUrl(url);

                // save pdf document
                doc.Save(Response, false, "Reporte.pdf");

                // close pdf document
                doc.Close();

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


    }
}